SELECT ORG_UNIT."ID",FORMMAIN_1679.FIELD0002 name,CASE WHEN pre."ID" IS NULL THEN 670869647114347 ELSE pre."ID" END supid,
(CASE WHEN FORMMAIN_1679.FIELD0009 = '2' THEN '1' ELSE '0' END) is_state
FROM FORMMAIN_1679 
LEFT JOIN ORG_UNIT ON ORG_UNIT.CODE = FORMMAIN_1679.FIELD0001 AND ORG_UNIT.IS_DELETED = 0
LEFT JOIN ORG_UNIT pre ON "SUBSTR"(ORG_UNIT."PATH",0,"LENGTH"(ORG_UNIT."PATH")-4) = pre."PATH" 
AND "LENGTH"("SUBSTR"(ORG_UNIT."PATH",0,"LENGTH"(ORG_UNIT."PATH")-4)) > 8
WHERE ORG_UNIT.CODE IS NOT NULL  AND (
FORMMAIN_1679.FIELD0002 != ORG_UNIT."NAME"
OR FORMMAIN_1679.FIELD0004 != pre.CODE OR
(CASE WHEN FORMMAIN_1679.FIELD0009 = '2' THEN '1' ELSE '0' END) != ORG_UNIT.IS_ENABLE 
)